<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/9/28
 * Time: 15:32
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Report extends Base
{
    public function index()
    {
        if (request()->isAjax()) {
            extract(input());
            $map = array();
            $page = input('page') ? input('page') : 1;
            $limit = input("limit") ? input("limit") : 10;// 获取总条数;
            if (isset($keyword) && $keyword != "") {
                $map['uuu.user_username|uuu.user_phone'] = ['like', "%" . $keyword . "%"];
            }
            if (isset($feedback_status) && $feedback_status != "") {
                $map['a.one_tousu'] = $feedback_status;
            }
//            if (isset($feedback_type_id) && $feedback_type_id != "") {
//                $map['a.feedback_type_id'] = $feedback_type_id;
//            }
//            if (isset($feedback_end) && $feedback_end != "") {
//                $map['a.feedback_end'] = $feedback_end;
//            }
//            if (isset($start) && $start != "" && isset($end) && $end == "") {
//                $map['a.feedback_time'] = ['>= time', $start];
//            }
//            if (isset($end) && $end != "" && isset($start) && $start == "") {
//                $map['a.feedback_time'] = ['<= time', $end];
//            }
//            if (isset($start) && $start != "" && isset($end) && $end != "") {
//                $map['a.feedback_time'] = ['between time', [$start, $end]];
//            }
            $map['one_tousu'] = array('IN',array(2,3));
            $count = Db::table('up_one_to_one')->alias('a')
                ->join('up_u_user uuu', 'uuu.user_id = a.one_student_id', 'left')
                ->join('up_u_user uuu1', 'uuu1.user_id = a.one_teacher_id', 'left')
                ->where($map)
                ->count();
            $list = Db::table('up_one_to_one')->alias('a')
                ->where($map)
                ->join('up_u_user uuu', 'uuu.user_id = a.one_student_id', 'left')
                ->join('up_u_user uuu1', 'uuu1.user_id = a.one_teacher_id', 'left')
                ->field('uuu.user_username,uuu.user_phone,uuu1.user_username as user_username1,a.*')
                ->page($page, $limit)
                ->select();//计算总页面

            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $list]);
        }
        return $this->fetch();
    }

    //删除
    public function del()
    {
        $id = input('param.id');
        $res = Db::table('up_feedback')->where('feedback_id', $id)->delete();
        if ($res) {
            return json(['code' => 200, 'msg' => '删除成功']);
        } else {
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }

    public function reject()
    {
        if (Request::instance()->isPost()) {
            $ids = input('param.id');
            $data['one_tousu'] = 3;
            $data['one_tousu_result'] = input('param.reject');
            $res = Db::table('up_one_to_one')->where('one_id', $ids)->update($data);
            if ($res) {
                return json(['code' => 200, 'msg' => '处理成功']);
            } else {
                return json(['code' => 100, 'msg' => '处理失败']);
            }
        }
        $id = input('param.one_id');
        $this->assign('id', $id);
        return $this->fetch();
    }
}